package com.znf4.controller.platform.resource.human;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.znf4.enums.OperationStatusEnum;
import com.znf4.id.IdGenerator;
import com.znf4.platform.resource.human.entity.Human;
import com.znf4.platform.resource.human.server.HumanServer;

/**
 * 平台人力资源信息
 */
@Controller
@RequestMapping("/platfrom/human")
public class HumanController {
	
	@Autowired
	private HumanServer humanServer ;
	
	@Autowired
	private IdGenerator idGenerator ;
	

	/**
	 * 函数功能说明 ： 添加人力资源
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.POST, RequestMethod.GET })
	public String add(Human human , Model model) {
		
		
		human.setId(idGenerator.getPlatformRresourceHumanNumber());
		
		humanServer.addHuman(human);
		
		model.addAttribute("status", OperationStatusEnum.SUCCESS.getDesc() );
		return "good/list";
	}

	
	
	/**
	 * 函数功能说明 ： 修改人力资源信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/update", method = { RequestMethod.POST, RequestMethod.GET })
	public String update(Human human , Model model) {
		
		humanServer.updateHuman(human);
		model.addAttribute("status", OperationStatusEnum.SUCCESS.getDesc() );
		return "good/list";
	}

	/**
	 * 函数功能说明 ： 删除人力资源信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delOne", method = { RequestMethod.POST, RequestMethod.GET })
	public String delOne(Human human , Model model) {
		
		humanServer.delOneHuman(human);
		model.addAttribute("status", OperationStatusEnum.SUCCESS.getDesc() );
		return "good/list";
	}

	/**
	 * 函数功能说明 ： 删除多条人力资源信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delAll", method = { RequestMethod.POST, RequestMethod.GET })
	public String delAll(String[] humans  , Model model) {
		
		List<Human> list = new ArrayList<>() ;
		for(int i=0 ; i < humans.length ; i ++ ){
			Human human = new Human() ;
			human.setId(humans[i]);
			list.add(human) ;
		}
		humanServer.delAllHuman(list);
		model.addAttribute("status", OperationStatusEnum.SUCCESS.getDesc() );
		return "good/list";
	}
	

	/**
	 * 函数功能说明 ： 获取人力资源
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/queryAll", method = { RequestMethod.POST, RequestMethod.GET })
	public String queryAll(Human human , Model model) {
		
		List<Human> list = humanServer.queryAll(human);
		model.addAttribute("status", OperationStatusEnum.SUCCESS.getDesc() );
		model.addAttribute("data", list );
		return "good/list";
	}
	
	

}
